package rep

import (
    "../pb"
    "../common"
    "../store"
    "sync"
)

type ReplicaInfo struct {
    pid              string
    offset           int64
    lastCommitTimeMs uint64
}

type Replica struct {
    mu                           sync.RWMutex
    repConfig                    *pb.ReplicaConfiguration
    createTimeMs                 uint64
    lastConfigChangeTimeMs       uint64
    lastCheckpointGenerateTimeMs uint64
    myNode                       *common.Node
    //prepare_list *_prepare_list;
    //mutation_log_ptr _private_log;
    //replication_options *_options;
    checkpointTimer *common.Task
    
    primaryState            PrimaryContext
    secondaryState          SecondContext
    potentialSecondaryState PotentialSecondaryContext
    inactiveIsTransient     bool
    isInitializing          bool
    
    store       store.Store
    prepareList store.PrepareList
}

func (r *Replica) Addr() string {
    r.mu.RLock()
    defer r.mu.RUnlock()
    return r.myNode.Addr("")
}

func (r *Replica) isConnected() bool {
    return true
}
func (r *Replica) pid() string {
    r.mu.RLock()
    defer r.mu.RUnlock()
    return r.repConfig.Pid
}

func (r *Replica) offsets() (int64, int64, int64, int64) { //maxprepared commited  prepared durable

}

func (r *Replica) initState(pid string) {
    r.mu.Lock()
    defer r.mu.Unlock()
    r.inactiveIsTransient = false;
    r.isInitializing = false;
    r.repConfig = &pb.ReplicaConfiguration{
        Ballot: 0,
        Pid:    pid,
        Status: pb.PartitionStatus_PS_Inactive,
    }
    r.createTimeMs = common.NowMillisecond()
    r.lastConfigChangeTimeMs = r.createTimeMs
    r.lastCheckpointGenerateTimeMs = r.createTimeMs
}
